/*! 
 * jquery.event.keyend - v 1.0.0 - http://jquery-ux.com/
 * Copyright (c) 2010 Michael Helgeson, Three Dub Media
 * Open Source MIT License - http://jquery-ux.com/license 
 */
// Created: 2009-09-24
// Updated: 2010-01-08
// REQUIRES: jquery 1.3+

;(function($){ // secure $ jQuery alias

// add the jquery instance method
$.fn.keyend = function( fn ){
	return this[ fn ? "bind" : "trigger" ]( "keyend", fn );
	};
	
// configure the special event
var keyend = $.event.special.keyend = {
	
	// timeout after each keypress
	delay: 420, // {Number} milliseconds
	
	// configure the interactions
	setup: function( opts ){ 
		opts = opts || {};
		// bind the key event to monitor typing
		$.event.add( this, "keydown", keyend.handler, {
			delay: opts.delay == undefined ? keyend.delay : opts.delay
			});
		},
	
	// destroy the configure interaction
	teardown: function(){
		// remove the key event
		$.event.remove( this, "keydown", keyend.handler );
		},
	
	// handle the key event
	handler: function( event ){
		// declare local refs
		var elem = this, data = event.data || {};
		// stop previous timer
		clearTimeout( data.timer );
		// set a new timer
		data.timer = setTimeout(function(){
			// hijack and handle the event
			event.type = 'keyend';
			$.event.handle.call( elem, event );
			}, data.delay );
		}	
	};

})( jQuery ); // confine scope